﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CHPM.IC.ServiceLocator;
using CHPM.PL.DesktopUI.Interfaces;
using CHPM.PL.DesktopUI.Presenters;
using CHPM.PL.DesktopUI.ServiceReference1;

namespace CHPM.PL.DesktopUI.UserControls
{
    public partial class MainGridControl : UserControl, IMainGrid
    {
        public MainGridControl(IServiceLocator serviceLocator)
        {
            InitializeComponent();
            dataGridView1.ColumnHeadersBorderStyle = ProperColumnHeadersBorderStyle;
        }

        static DataGridViewHeaderBorderStyle ProperColumnHeadersBorderStyle
        {
            get
            {
                return (SystemFonts.MessageBoxFont.Name == "Segoe UI") ?
                DataGridViewHeaderBorderStyle.None :
                DataGridViewHeaderBorderStyle.Raised;
            }
        }

        public event GetPatientsHandler OnGetPatients;

        public void SetDataSource(List<PATIENT> patients)
        {
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

            dataGridView1.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn firstColumn = new DataGridViewTextBoxColumn();
            firstColumn.DataPropertyName = "Id";
            firstColumn.HeaderText = "Patient id";

            dataGridView1.Columns.Add(firstColumn);

            DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();
            nameColumn.DataPropertyName = "FULLNAME";
            nameColumn.HeaderText = "Name";

            dataGridView1.Columns.Add(nameColumn);

            DataGridViewTextBoxColumn phoneColumn = new DataGridViewTextBoxColumn();
            phoneColumn.DataPropertyName = "PHONE";
            phoneColumn.HeaderText = "Number";

            dataGridView1.Columns.Add(phoneColumn);

            DataGridViewTextBoxColumn cardColumn = new DataGridViewTextBoxColumn();
            cardColumn.DataPropertyName = "CARD";
            cardColumn.HeaderText = "Card";

            dataGridView1.Columns.Add(cardColumn);

            dataGridView1.DataSource = patients;
            dataGridView1.ReadOnly = true;

        }

        public Control AsControl
        {
            get { return this; }
        }

        private void MainGridControl_Load(object sender, EventArgs e)
        {
            OnGetPatients();
        }
    }
}
